extends ../layout

block css
    link(rel='stylesheet', href='/css/base/ck_base.css', media='screen')
    link(rel='stylesheet', href='/css/user/ck_set.css', media='screen')
block js
    script(src='/js/jquery-1.8.0.min.js')
    script(src='/js/html5.js')
    script(src='/js/jquery.common.js')
    script(src='/js/user/util.js')
    
block content

    .set_wrap.clearfix
      aside.set_sidebar
        .nav_hd 设置中心
        ul.sidetab
          li
            a.icoR_11(href='/info') 个人资料
          li.curr
            a.icoR_20(href='/info/address') 收货地址
          li
            a.icoR_12(href='/info/icon') 设置头像
          li
            a.icoR_15(href='/info/pwd') 帐号安全
          li
            a.icoR_21(href='/info/school') 所在学校
      .set_content.personal_info.shipping_add.shipping_add_focus
        .pi_bd.clearfix
          .sa_title
            | 实物收货地址
            span.test
              | ( 
              em.c_f30 *
              |  该地址用于邮寄线下的教材、图书等实物 )
          form.formH.grzlForm.clearfix
            input#province(type='hidden', value='#{province}')
            input#city(type='hidden', value='#{city}')
            input#zone(type='hidden', value='#{zone}')
            .formItem.mb30.pb5
              label.form_label(for='')
                em.c_f30 *
                |  收件人：
              .form_field
                input#addressee.form_text.w230(type='text', value='#{addressee}')
            // =E formItem
            .formItem.mb20
              label.form_label(for='')
                em.c_f30 *
                |  手机：
              .form_field
                input#mobile.form_text(type='text', maxlength='11', value='#{mobile}')
            .formItem.mb20
              label.form_label(for='')
                em.c_f30 *
                |  所在城市：
              .form_field
                #cascader_city
            // =E formItem
            .formItem.mb20
              label.form_label(for='')
                em.c_f30 *
                |  详细地址：
              .form_field
                textarea#address(rows='10', cols='30') #{address}
            .formItem.mb20
              span(style='margin-left:10px;')
            // =E formItem
            .formItem.mb20
              label.form_label(for='')  
              .form_field
                p.mb10
                  a#saveBtn.n_btn38g(href='javascript:;') 保存
            // =E formItem
        // =E grzl_bd
      script.

        var data = !{JSON.stringify(_city)};
        var cascader_city = JSON.parse(data);
        //console.log(cascader_city);
        var addressee_text_tip = '真实姓名';
        var mobile_text_tip = '手机号码、电话号码必须填一项';
        var address_text_tip = '该地址用于邮寄线下的教材、图书等实物，请确保信息填写正确！';
        var checkAddressee = function(addressee) {
        if (addressee_text_tip == addressee) {
        return false;
        }
        var regular = /^[\\u4E00-\u9FA5A-Za-z]+$/g;
        if (!regular.test(addressee)) {
        return false;
        }
        return true;
        };
        var checkMobile = function(mobile) {
        if (mobile_text_tip == mobile) {
        return false;
        }
        var regular = /^[(86)|0]?(13\d{9})|(15\d{9})|(17\d{9})|(18\d{9})$/g;
        if (!regular.test(mobile)) {
        return false;
        }
        return true;
        };
        var checkAddress = function(address) {
        if (address_text_tip == address) {
        return false;
        }
        if (!address) {
        return false;
        }
        return true;
        };        
        var setHintFocus = function(o, c) {
        var text_val = o.val();
        var text_tip = c;
        o.css({ color: '#777' });
        if (text_val == text_tip) {
        o.val('');
        } 
        }
        var setHintBlur = function(o, c) {
        var text_val = o.val();
        var text_tip = c;
        if (text_val == '') {
        o.val(text_tip);
        o.css({ color: '#ccc' });
        } else if (text_val == text_tip) {
        o.css({ color: '#ccc' });
        } else {
        o.css({ color: '#777' });
        }
        }
        $(function() {
        $("#addressee").focus(function() {
        setHintFocus($("#addressee"), addressee_text_tip);
        }).blur(function() {
        setHintBlur($("#addressee"), addressee_text_tip);
        });
        $("#mobile").focus(function() {
        setHintFocus($("#mobile"), mobile_text_tip);
        }).blur(function() {
        setHintBlur($("#mobile"), mobile_text_tip);
        });
        $("#address").focus(function() {
        setHintFocus($("#address"), address_text_tip);
        }).blur(function() {
        setHintBlur($("#address"), address_text_tip);
        });
        $("#saveBtn").click(function() {
        var addressee = $("#addressee").val();
        var mobile = $("#mobile").val();
        var address = $("#address").val();
        var uid = $("#uid").val();
        var address = $("#address").val();
        var province = $("#province").val();
        var city = $("#city").val();
        var zone = $("#zone").val();
        if (checkAddressee(addressee) == false) {
        $.alertBoxy({ message: '收件人姓名只允许汉字或英文！' });
        return;
        }
        if (!mobile) {
        $.alertBoxy({ message: '请填写手机号！' });
        return;
        } else {
        if (checkMobile(mobile) == false) {
        $.alertBoxy({ message: '请填写正确的手机号！' });
        return;
        }
        }
        if (province == '') {
        $.alertBoxy({ message: '请选择所在城市！' });
        return;
        }
        if (checkAddress(address) == false) {
        $.alertBoxy({ message: '请填写详细地址！' });
        return;
        }
        var params = [
        "addressee=" + encodeURIComponent(addressee),
        "&mobile=" + mobile,
        "&address=" + encodeURIComponent(address),
        "&uid=" + encodeURIComponent(uid),
        "&province=" + encodeURIComponent(province),
        "&city=" + encodeURIComponent(city),
        "&zone=" + encodeURIComponent(zone)
        ].join('');
        var tipboxy = false;
        $.ajax({
        url: "/info/saveAddress",
        type: "post",
        data: params,
        dataType: "json",
        async: false,
        beforeSend: function() {
        tipboxy = $.tipsBoxy({ type: "loading", message: "数据提交中...", mask: true });
        },
        success: function(ret) {
        tipboxy.cancel();
        if (ret.code == 0) {
        $.tipsBoxy({ message: "收货地址保存成功", width: 200, height: 80 });
        } else {
        $.alertBoxy({ message: ret.result });
        }
        }
        });
        });
        });
      script(src='/js/user/city.js')
      
